//
//  NSString+Icon.m
//  FYDriver
//
//  Created by 于龙 on 15/10/9.
//  Copyright © 2015年 Foryou. All rights reserved.
//

#import "NSString+Icon.h"

@implementation NSString (Icon)

- (NSMutableAttributedString *)attributeStringWithIcon:(UIImage *)icon withBound:(CGRect)bounds Ahead:(BOOL)ishead{
    
    NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:self];
    NSTextAttachment *attachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    attachment.image = icon;
    attachment.bounds = bounds;
    NSAttributedString *iconString = [NSAttributedString attributedStringWithAttachment:attachment];
    if (ishead) {
        [attString insertAttributedString:iconString atIndex:0];
    } else {
        [attString insertAttributedString:iconString atIndex:self.length];
    }
    return attString;
}
@end
